<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<%@ include file="/taglibs.jsp"%>
<!-- 月历 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick-zh-CN.js"></script>
<!-- 時間 -->	
<script type="text/javascript" src="/js/jquery.timePicker.js"></script>
<link rel="stylesheet" type="text/css" href="/css/timePicker.css"/>
<script type="text/javascript" charset="UTF-8" src="/js/jquery-ui-1.7.2.custom.min.js"></script>
<link rel="stylesheet" type="text/css" href="/css/jquery-ui-1.7.2.custom.css"/>
<link rel="stylesheet" type="text/css" href="/css/smoothness.datepick.css" />
<script language="javascript">
	$().ready( function() {
		$('#startDate').datepick({minDate: null, showOn: 'both',dateFormat:"yy/mm/dd",yearRange: '-50:+50'});
		$('#endDate').datepick({minDate:new Date(), showOn: 'both',beforeShow:customRange,dateFormat:"yy/mm/dd",yearRange: '-50:+50'});
		function customRange (){
			var startDt = $('#startDate').val(); //起始日
			var endDt = new Date(parseInt(startDt.substring(0,4),10),parseInt(startDt.substring(5,7),10)-1,parseInt(startDt.substring(8,10),10)); //結束日
			return {minDate:endDt}; 
		}
		$("#startTime").timePicker();
		$("#endTime").timePicker();
	});	

	 $(function() {
		 $.formValidator.initConfig({formid:"campaignForm",onerror:function(msg){alert(msg)},onsuccess:function(){return true;}});
		 
		 $("#brief").htmlarea();
		 $("#description").htmlarea();
		 $("#details").htmlarea();

		 $("#submit_button").click(function(){
				if ($("#campaignName").val() == "" ){
					alert("请输入活动名稱");
				}
				
				if ($("#campaignType").val() == ""){
					alert("请选择活动类型 ");
					return false;
				}
				
				if ($("#startDate").val() == ""){
					alert("请输入活动起始日期");
					return false;
				}
				
				if ($("#endDate").val() == ""){
					alert("请输入活动结束日期");
					return false;
				}
				
				if ($("#startTime").val() == ""){
					alert("请输入活动起始时间");
					return false;
				}
				
				if ($("#endTime").val() == ""){
					alert("请输入活动结束时间");
					return false;
				}
				if ($("#endTime").val() == ""){
					alert("请选择适用会员等级");
					return false;
				}								
				//return false;
			});

		//栏位资料验证
		 $("#campaignName").formValidator({onfocus:"请输入活动名称",oncorrect:"请输入活动名称格式正确"}).inputValidator({min:2,max:40,onerror:"活动名称名稱不能超过40个字元之间且不能为空值"});
			
	 });		
</script>
<h1>行销活动管理</h1>
<s:form name="campaignForm" id="campaignForm" action="save.do" method="post">
<s:actionerror />
<s:actionmessage />
<s:fielderror />
<br />
<table class="tb-data" width="100%">
	<tr>
		<th>活动编号</th>
		<td><c:if test="${campaign.id eq null}">系统自动产生</c:if><c:if test="${!empty campaign.id}"><fmt:formatNumber pattern="0000" value="${campaign.id}"/></c:if></td>
	</tr>
	<tr>		
		<th>* 活动名称</th>
		<td><input name="campaignName" id="campaignName" size="40" value="${campaign.campaignName}"></td>
	</tr>
	<tr>		
		<th>活动说明</th>
		<td><textarea name="campaignDesc" id="campaignDesc" rows="4" cols="60">${campaign.campaignDesc}</textarea></td>
	</tr>
	<tr>
		<th>* 活动类型</th>
		<td>
		<select id="campaignType" name="campaignType">
			<option value="">== 请选择 ==</option>
			<option value="01" <c:if test="${campaign.campaignType eq '01'}">selected</c:if>>满额送积分</option>
			<option value="02" <c:if test="${campaign.campaignType eq '02'}">selected</c:if>>满额送折价券</option>
			<option value="03" <c:if test="${campaign.campaignType eq '03'}">selected</c:if>>满额直减</option>
			<option value="04" <c:if test="${campaign.campaignType eq '04'}">selected</c:if>>积分加倍送</option>
			<option value="05" <c:if test="${campaign.campaignType eq '05'}">selected</c:if>>加价购（搭售）</option>
			<option value="06" <c:if test="${campaign.campaignType eq '06'}">selected</c:if>>免运费</option>
			<option value="07" <c:if test="${campaign.campaignType eq '07'}">selected</c:if>>n 选 m</option>
			<option value="08" <c:if test="${campaign.campaignType eq '08'}">selected</c:if>>红配录</option>
			<option value="09" <c:if test="${campaign.campaignType eq '09'}">selected</c:if>>组合商品</option>
			<option value="10" <c:if test="${campaign.campaignType eq '10'}">selected</c:if>>赠品</option>
			<option value="11" <c:if test="${campaign.campaignType eq '11'}">selected</c:if>>加一元送一件</option>
			<option value="12" <c:if test="${campaign.campaignType eq '12'}">selected</c:if>>第二件n折</option>
			<option value="13" <c:if test="${campaign.campaignType eq '13'}">selected</c:if>>买 n 送一</option>
		</select>		
		<input name="campaignType" id="campaignType" size="40" value="${campaign.campaignType}"></td>
	</tr>
	<tr>		
		<th>活动类型设定值</th>
		<td><input name="campaignTypeExtension" id="campaignTypeExtension" size="40" value="${campaign.campaignTypeExtension}"></td>
	</tr>
	<tr>
		<th>* 活动起始日期时间</th>
		<td>
		<input name="startDate" id="startDate" size="20" value="<fmt:formatDate value="${campaign.startDateTime}" pattern="yyyy/MM/dd"/>">
		<input name="startTime" id="startTime" size="20" value="<fmt:formatDate value="${campaign.startDateTime}" pattern="HH:mm"/>">
		</td>
	</tr>
	<tr>
		<th>* 活动结束日期时间</th>
		<td>
		<input name="endDate" id="endDate" size="20" value="<fmt:formatDate value="${campaign.endDateTime}" pattern="yyyy/MM/dd"/>">
		<input name="endTime" id="endTime" size="20" value="<fmt:formatDate value="${campaign.endDateTime}" pattern="HH:mm"/>"></td>
	</tr>
	<tr>		
		<th>* 适用会员等级</th>
		<td><input name="allowMemberRank" id="allowMemberRank" size="20" value="${campaign.allowMemberRank}"></td>
	</tr>
	<tr>
		<th>* 适用时机</th>
		<td>
			<select id="displayTiming" name="displayTiming">
				<option value="">== 请选择 ==</option>
				<option value="PRD_PGE" <c:if test="${campaign.displayTiming eq 'PRD_PGE'}">selected</c:if>>商品页</option>
				<option value="SHP_CRT" <c:if test="${campaign.displayTiming eq 'SHP_CRT'}">selected</c:if>>购物车</option>
				<option value="CHK_OUT" <c:if test="${campaign.displayTiming eq 'CHK_OUT'}">selected</c:if>>结帐页</option>
				<option value="ORD_FNH" <c:if test="${campaign.displayTiming eq 'ORD_FNH'}">selected</c:if>>订单成立后</option>
			</select>	
		
		<input name="displayTiming" id="displayTiming" size="20" value="${campaign.displayTiming}"></td>
	</tr>
	<tr>
		<th>适用范围</th>
		<td>
			<select id="applyRange" name="applyRange">
				<option value="">== 请选择 ==</option>
				<option value="ALL" <c:if test="${campaign.applyRange eq 'ALL'}">selected</c:if>>耀点全站</option>
				<option value="CAT" <c:if test="${campaign.applyRange eq 'CAT'}">selected</c:if>>特定分类／目录</option>
				<option value="PRD" <c:if test="${campaign.applyRange eq 'PRD'}">selected</c:if>>特定商品</option>
				<option value="BRD" <c:if test="${campaign.applyRange eq 'BRD'}">selected</c:if>>特定品牌</option>
			</select>	
		<input name="applyRange" id="applyRange" size="20" value="${campaign.applyRange}"></td>
	</tr>
	<tr>
		<th>适用范围设定值</th>
		<td><input name="applyRangeExtension" id="applyRangeExtension" size="20" value="${campaign.applyRangeExtension}"></td>
	</tr>
	<tr>
		<th>最低订单金额</th>
		<td><input name="minOrderAmount" id="minOrderAmount" size="20" value="${campaign.minOrderAmount}"></td>
	</tr>
	<tr>
		<th>最高订单金额</th>
		<td><input name="maxOrderAmount" id="maxOrderAmount" size="20" value="${campaign.maxOrderAmount}"></td>
	</tr>
	<tr>
		<th>搭售范围型态</th>
		<td>
			<select id="addonType" name="addonType">
				<option value="">== 请选择 ==</option>
				<option value="ALL" <c:if test="${campaign.addonType eq 'ALL'}">selected</c:if>>耀点全站</option>
				<option value="CAT" <c:if test="${campaign.addonType eq 'CAT'}">selected</c:if>>特定分类／目录</option>
				<option value="PRD" <c:if test="${campaign.addonType eq 'PRD'}">selected</c:if>>特定商品</option>
				<option value="BRD" <c:if test="${campaign.addonType eq 'BRD'}">selected</c:if>>特定品牌</option>
			</select>	
		<input name="addonType" id="addonType" size="20" value="${campaign.addonType}"></td>
	</tr>		
	<tr>
		<th>搭售范围型态设定值</th>
		<td><input name="addonTypeExtension" id="addonTypeExtension" size="20" value="${campaign.addonTypeExtension}"></td>
	</tr>		
	<tr>
		<th>* 启用否？</th>
		<td>
			<input type="radio" name="enable" id="enable" value="Y" <c:if test="${campaign.enable eq 'Y' || campaign.enable == null}">checked</c:if>> 是　
			<input type="radio" name="enable" id="enable" value="N" <c:if test="${campaign.enable eq 'N'}">checked</c:if>> 否
	</tr>		
	<tr>
		<th>备注</th>
		<td><textarea name="campaignDesc" id="campaignDesc" rows="4" cols="60">${campaign.memo}</textarea></td>
	</tr>
	<tr>
		<td colspan="2">
			<div class="f-link">
				<input type="submit" name="submitButton" value="储存修改"/>
				<a href="#" onclick="document.campaignForm.submit();" >储存修改</a>
				<a href="list.do">回活动查询页</a>
			</div>
		</td>
	</tr>		
</table>
</s:form>
<div class="f-link">
	<a href="#" onclick="this.form.submit();" >储存修改</a>
	<a href="list.do">回活动查询页</a>
</div>